﻿using AntdUI;
using BST250301TestStand.Models;
using MySql.Data.MySqlClient;
using Mysqlx.Crud;
using NPOI.SS.Formula.Functions;
using NPOI.SS.Formula.PTG;
using NPOI.SS.UserModel;
using NPOI.Util;
using NPOI.XSSF.UserModel; // 用于 .xlsx 文件
using ScottPlot;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BST250301.Views
{
    public partial class AlarmLog : UserControl
    {
        AntList<AlarmItem> antList = new AntList<AlarmItem>();
        private AntdUI.Window window;
        public AlarmLog()
        {
            InitializeComponent();
            this.datePicker1.Value = DateTime.Now;
            this.datePicker2.Value = DateTime.Now;
            InitData();
            InitTableColumns();
            BindEventHandler();

        }

        private void BindEventHandler()
        {
        }

        private void InitData()
        {
            antList = DB.GetAlarmLog(datePicker1.Value, datePicker2.Value);
            table_base.Binding(antList);
            selectCode.Items.Clear();
            selectType.Items.Clear();
            selectCode.Items.AddRange(antList.Select(p => p.Code).ToArray());
            selectType.Items.AddRange(antList.Select(p => p.ByEQ).ToArray());

            table_base.Bordered = true;
        }
        private void InitTableColumns()
        {
            table_base.Columns = new ColumnCollection() {
                new AntdUI.Column("Id", "ID",ColumnAlign.Center),
                new AntdUI.Column("Code", "报警编码",ColumnAlign.Center),
                new AntdUI.Column("ByEQ", "触发设备",ColumnAlign.Center),
                new AntdUI.Column("ResetState", "复位标志",ColumnAlign.Center),
                new AntdUI.Column("DTAlmarm", "触发时间",ColumnAlign.Center),
            };
        }


        private void btnRefrence_Click(object sender, EventArgs e)
        {
            InitData();
        }
        private void Table_base_CellClick(object sender, TableClickEventArgs e)
        {

        }
        private void PlotDemo()
        {
            ScottPlot.Plot myPlot = new();

            double[] values = Generate.RandomNormal(500, stdDev: 0.2);

            for (int i = 1; i < 10; i++)
            {
                var sig = myPlot.Add.Signal(values);
                sig.Data.YOffset = i * 3;
                sig.LineWidth = 1.5f;
                values = Generate.AddSin(values, oscillations: i);
            }
            formsPlot1.Multiplot.AddPlot(myPlot);
            formsPlot1.Refresh();
        }

        private void selectCode_SelectedIndexChanged(object sender, IntEventArgs e)
        {
            antList.Select(p=>p.Code == selectCode.Text);
        }
    }
}
